<?php
	
	/**
	 * 操作问题表的模型
	 */
	class AskModel extends Model{
		public function __construct($table){
			parent::__construct($table);
		}
		
		/**
		 * 添加问题
		 * @param array $post 添加的内容
		 * @return int $query 返回添加的条数
		 */
		 public function addAsk($post,$exp){
		 	//给用户添加问答数  金币 还有经验
		 	$this->_exec("UPDATE hd_user SET ask=ask+1,exp=exp+{$exp} WHERE uid={$post['uid']}");
			
		 	$query = $this->_exec("INSERT INTO hd_ask(content,time,reward,uid,cid) VALUES('{$post['content']}','{$post['time']}','{$post['reward']}','{$post['uid']}','{$post['cid']}')");
			if($query){
				return $this->getinsertid();
			}
		 }
		
		 /**
		  * 显示相应ID的提问数据
		  */
		  public function getAsk($asid){
		  	$query = $this->query("SELECT exp,cid,asid,content,time,solve,username,u.uid as uuid,a.answer as aanswer,reward FROM hd_ask as a JOIN hd_user as u ON a.uid=u.uid WHERE asid = {$asid}");
			return $query;
		  }
		
		/**
		 * 显示相应问题的回答数据
		 */
		 public function getAnswer($asid){
		 	$query = $this->query("SELECT exp,anid,username, USER .uid, content, time, an.accept, asid, face FROM hd_answer AS an INNER JOIN hd_user AS USER ON an.uid = USER .uid WHERE asid = {$asid} ORDER BY time DESC");
			
//			var_dump($query);
			return $query;
			
		 }
		 /**
		  * ajax搜索问题
		  */
//		  
//		  public function ajaxKeyWord($key){
//		  	$query = $this->query("SELECT * FROM hd_ask WHERE ");
//		  }
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
